package com.yunkaweilai.android.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.Html;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;

import com.yunkaweilai.android.R;
import com.yunkaweilai.android.interfaces.MyDialogInterfaceForCoupon;


/**
 * 通用dialog
 * MyDialogInterface 为接口
 * 取消确定按钮
 * Created by K on 2019/07/15
 */

public class MyDialogForCoupon extends Dialog {
    private TextView id_tv_max_type;
    private TextView idTvContent;
    private TextView idTvRight;
    private TextView idTvClose;
    private MyDialogInterfaceForCoupon mMyDialogInterface;
    private String title;
    private String content;
    private CheckBox rb1;
    private CheckBox rb2;
    private String type = "no_send";
    private boolean sms = false;
    private boolean wechat = false;

    public MyDialogForCoupon(@NonNull Context context, MyDialogInterfaceForCoupon MyDialogInterface, String title, String content,boolean sms,boolean wechat) {
        super(context, R.style.dialog);
        this.title = title;
        this.content = content;
        this.mMyDialogInterface = MyDialogInterface;
        this.sms = sms;
        this.wechat = wechat;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_points_change_coupon);
        initview();

        id_tv_max_type.setText(Html.fromHtml(title));
        idTvContent.setText(Html.fromHtml(content));

        if (!sms){
            rb1.setAlpha((float)0.3);
            rb1.setClickable(false);
        }else {
            rb1.setAlpha((float)1);
            rb1.setClickable(true);
        }
        if (!wechat){
            rb2.setAlpha((float)0.3);
            rb2.setClickable(false);
        }else {
            rb2.setAlpha((float)1);
            rb2.setClickable(true);
        }

        idTvRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (rb1.isChecked() && rb2.isChecked()) {
                    type = "all";
                } else if (!rb1.isChecked() && rb2.isChecked()) {
                    type = "wechat";
                } else if (rb1.isChecked()&&!rb2.isChecked()) {
                    type = "sms";
                } else {
                    type = "no_send";
                }
                mMyDialogInterface.RightClick(type);
                dismiss();
            }
        });
        idTvClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mMyDialogInterface.CancelClick();
                dismiss();
            }
        });

    }

    private void initview() {
        idTvContent = ((TextView) findViewById(R.id.id_tv_content));
        idTvRight = ((TextView) findViewById(R.id.id_tv_right));
        idTvClose = ((TextView) findViewById(R.id.id_tv_close));
        id_tv_max_type = ((TextView) findViewById(R.id.id_tv_max_type));
        rb1 = (CheckBox) findViewById(R.id.id_rb1);
        rb2 = (CheckBox) findViewById(R.id.id_rb2);
        Drawable drawable = getContext().getResources().getDrawable(R.drawable.selector_checkbox_style);
        //设置drawable对象的大小
        drawable.setBounds(0, 0, 40, 40);
        Drawable drawable2 = getContext().getResources().getDrawable(R.drawable.selector_checkbox_style);
        //设置drawable对象的大小
        drawable2.setBounds(0, 0, 40, 40);
        rb1.setCompoundDrawables(drawable, null, null, null);
        rb2.setCompoundDrawables(drawable2, null, null, null);
    }

}
